import React from 'react'
import { Tabs, Table, Modal, Badge } from 'antd'
import moment from "moment"
import { SIGTERM } from 'constants';

const TabPane = Tabs.TabPane;
const confirm = Modal.confirm

class List extends React.Component {
	constructor(props) {
		super(props)

		this.state = {

		}
	}

	edit = (record, e, text) => {
		const { showDet1, onComponent, isFileComponent, getCover } = this.props
		const param = {
			id: record.id,
			operatingType: 0,
		}
		const params = {
			documentId: record.id,
			type: 0,
		}
		const paramms11 = {
			documentId: record.id,
		}
		if (e == 1) {
			getCover(paramms11)
			showDet1(param)
			isFileComponent(false)
		} else if (e == 2) {
			confirm({
				title: '您确定要归档这条记录吗?',
				onOk() {
					onComponent(params)
				}
			})
		}

	}
	async pageChange(pagination) {
		await this.props.onPageChange(pagination);
		this.newPage = pagination.current;
	}
	editComponent = (record, e, text) => {
		const { showDet, isFileComponent } = this.props
		const param = {
			id: record.id,
			operatingType: 0,
		}
		showDet(param)
		isFileComponent(true)
	}

	render() {
		const { menu, list, pagination, loading } = this.props
		// console.log(pagination)
		const columns1 = [
			{
				title: "申请人",
				dataIndex: "applyName",
				key: "applyName",
				render: (text, record) => {
					const datas = text.split("#")
					const ary = []
					datas.map((item, i) => {
						ary.push(
							<p>{item}</p>
						)
					})
					return ary
				}
			}, {
				title: "身份证号码",
				dataIndex: "idcard",
				key: "idcard",
				render: (text, record) => {
					if(!text){
						return null
					}
					const datas = text.split("#")
					const ary = []
					datas.map((item, i) => {
						ary.push(
							<p>{item}</p>
						)
					})
					return ary
				}
			}, {
				title: "公证事项",
				dataIndex: "notarialMatters",
				key: "notarialMatters",
				render: (text, record) => {
					const datas = text.split("#")
					const ary = []
					datas.map((item, i) => {
						ary.push(
							<p>{item}</p>
						)
					})
					return ary
				}
			}, {
				title: "公证号码",
				dataIndex: "notaryNumber",
				key: "notaryNumber",
				render: (text, record) => {
					const datas = text.split("#")
					const ary = []
					datas.map((item, i) => {
						ary.push(
							<p>{item}</p>
						)
					})
					return ary
				}
			}, {
				title: "承办人",
				dataIndex: "contractorUserName",
				key: "contractorUserName",
			}, {
				title: "建档人",
				dataIndex: "createdUserName",
				key: "createdUserName",
			}, {
				title: "收件日期",
				dataIndex: "createdTime",
				key: "createdTime",
				render: (text, record) => {
					return (
						<p>
							{
								moment(record.createdTime).format("YYYY-MM-DD")
							}
						</p>
					)
				}
			}, {
				title: "公证日期",
				dataIndex: "notarizationAt",
				key: "notarizationAt",
				render: (text, record) => {
					return (
						<p>
							{
								moment(record.notarizationAt).format("YYYY-MM-DD")
							}
						</p>
					)
				}
			}, {
				title: '操作',
				dataIndex: 'applicationState',
				key: 'applicationState',
				render: (text, record) => {
					return (
						<div>
							{menu == 0 ?
								<div>
									<span onClick={this.edit.bind(null, record, 1)} style={{ marginRight: 5 }}><a href="#">查看</a></span>
									{record.operatingType != 0 ?
										<span onClick={this.edit.bind(null, record, 2)} style={{ marginRight: 5 }}><a href="#">申请归档</a></span> :
										record.auditState == undefined || record.auditState == 2 ?
											<span onClick={this.edit.bind(null, record, 2)} style={{ marginRight: 5 }}><a href="#">申请归档</a></span> :
											''
									}
								</div> :
								menu == 1 ?
									<div>
										{record.applicationState == 0 ?
											<span onClick={this.editComponent.bind(null, record, 1)} style={{ marginRight: 5 }}><a href="#">审核</a></span> :
											record.auditState == 1 ?
												<div><Badge status="success" /><span>通过</span></div> :
												<div><Badge status="error" /><span>拒绝</span></div>
										}
									</div> : ""
							}

						</div>
					)
				}
			}
		];
		const columns = [
			{
				title: "档案年度",
				dataIndex: "documentYear",
				key: "documentYear",
			}, {
				title: "公证事项",
				dataIndex: "notarialMatters",
				key: "notarialMatters",
				render: (text, record) => {
					const datas = text.split("#")
					const ary = []
					datas.map((item, i) => {
						ary.push(
							<p>{item}</p>
						)
					})
					return ary
				}
			},
			{
				title: "申请人",
				dataIndex: "applyName",
				key: "applyName",
				render: (text, record) => {
					const datas = text.split("#")
					const ary = []
					datas.map((item, i) => {
						ary.push(
							<p>{item}</p>
						)
					})
					return ary
				}
			},
			{
				title: "收件日期",
				dataIndex: "createdTime",
				key: "createdTime",
				render: (text, record) => {
					return (
						<p>
							{
								moment(record.createdTime).format("YYYY-MM-DD")
							}
						</p>
					)
				}
			},
			{
				title: "公证日期",
				dataIndex: "notarizationAt",
				key: "notarizationAt",
				render: (text, record) => {
					return (
						<p>
							{
								moment(record.notarizationAt).format("YYYY-MM-DD")
							}
						</p>
					)
				}
			},
			{
				title: "承办人",
				dataIndex: "contractorUserName",
				key: "contractorUserName",
			},
			{
				title: "建档人",
				dataIndex: "createdUserName",
				key: "createdUserName",
			},
			{
				title: "所属机构",
				dataIndex: "organizationName",
				key: "organizationName",
			},
			{
				title: "申请提交日期",
				dataIndex: "applicationCreatedTime",
				key: "applicationCreatedTime",
				render: (text, record) => {
					return (
						<p>
							{
								moment(record.applicationCreatedTime).format("YYYY-MM-DD")
							}
						</p>
					)
				}
			},
			{
				title: "状态",
				dataIndex: "applicationState",
				key: "applicationState",
				render: (text, record) => {
					return (
						<div>
							{record.applicationState == 0 ?
								<div><Badge status="processing" /><span>待审核</span></div> :
								record.applicationState == 1 ?
									<div><Badge status="success" /><span>通过</span></div> :
									record.applicationState == 2 ?
										<div><Badge status="error" /><span>拒绝</span></div> :
										<div><Badge status="success" /><span>通过</span></div>
							}
						</div>
					)
				}
			},
			{
				title: '操作',
				dataIndex: 'operation',
				key: 'operation',
				render: (text, record) => {
					return (
						<div>
							{menu == 0 ?
								<div>
									<span onClick={this.edit.bind(null, record, 1)} style={{ marginRight: 5 }}><a href="#">查看</a></span>
									{record.operatingType != 0 ?
										<span onClick={this.edit.bind(null, record, 2)} style={{ marginRight: 5 }}><a href="#">申请归档</a></span> :
										record.auditState == undefined || record.auditState == 2 ?
											<span onClick={this.edit.bind(null, record, 2)} style={{ marginRight: 5 }}><a href="#">申请归档</a></span> :
											''
									}
								</div> :
								menu == 1 ?
									<div>
										{record.applicationState == 0 ?
											<span onClick={this.editComponent.bind(null, record, 1)} style={{ marginRight: 5 }}><a href="#">审核</a></span> :
											record.auditState == 1 ?
												<div><Badge status="success" /><span>通过</span></div> :
												<div><Badge status="error" /><span>拒绝</span></div>
										}
									</div> : 
									menu == 2 ?
									"":
									<span onClick={this.edit.bind(null, record, 1)} style={{ marginRight: 5 }}><a href="#">查看</a></span>
							}

						</div>
					)
				}
			}
		];
		columns.map((item, i) => {
			if (item.title == "申请提交日期") {
				menu == 1 ? '' : delete columns[i]
			}
			if (item.title == "状态") {
				menu == 3 || menu == 2 ? '' : delete columns[i]
			}
			if (item.title == "操作") {
				menu == 2 ? delete columns[i] : ''
			}
		})

		return (
			<div>
				{menu == 0 ?
					<Table
						columns={columns1}
						dataSource={list}
						loading={loading}
						onChange={this.pageChange.bind(this)}
						pagination={pagination}
						rowKey={record => record.endAt}
					/> :
					<Table
						columns={columns}
						dataSource={list}
						loading={loading}
						onChange={this.pageChange.bind(this)}
						pagination={pagination}
						rowKey={record => record.endAt}
					/>
				}

				{/* {menu == 0 ?
					<Table
						columns={columns}
						dataSource={list}
						loading={loading}
						onChange={this.pageChange.bind(this)}
						pagination={pagination1}
						rowKey={record => record.endAt}
					/> :
					menu == 1 ?
						<Table
							columns={columnss}
							dataSource={list1}
							loading={loading}
							onChange={this.pageChange.bind(this)}
							pagination={pagination2}
							rowKey={record => record.endAt}
						/> :
						<Table
							columns={columnss1}
							dataSource={list2}
							loading={loading}
							onChange={this.pageChange.bind(this)}
							pagination={pagination3}
							rowKey={record => record.endAt}
						/>
				} */}

			</div>
		)
	}
}

export default List